﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace Meraz.Core.Model
{
    [Serializable]
    [DataContract]
    public class TwitterLink : IEquatable<TwitterLink>
    {
        [DataMember]
        public int Sequence { get; set; }
        [DataMember]
        public long TweetID { get; set; }
        [DataMember]
        public int UrlID { get; set; }
        [DataMember]
        public string Tone
        {
            get { return this.ToneType.ToString(); }
            set
            {
                if (string.IsNullOrWhiteSpace(value))
                    this.ToneType = ToneType.Undefined;
                else
                {
                    try
                    {
                        this.ToneType = (ToneType)Enum.Parse(typeof(ToneType), value);
                    }
                    catch
                    {
                        this.ToneType = ToneType.Undefined;
                    }
                }
            }
        }
        public ToneType ToneType { get; set; }
        [DataMember]
        public virtual Url Url { get; set; }
        [DataMember]
        public bool IsInternal { get; set; }
        [DataMember]
        public bool IsError { get; set; }
        [DataMember]
        public string Original { get; set; }

        public override bool Equals(object obj)
        {
            if (obj == null)
                return false;

            if (obj is TwitterLink)
                return Equals((TwitterLink)obj);
            return false;
        }
        public override int GetHashCode()
        {
            return TweetID.GetHashCode() ^ UrlID.GetHashCode();
        }
        public bool Equals(TwitterLink other)
        {
            if (other == null)
                return false;
            if (TweetID != other.TweetID)
                return false;
            return (UrlID == other.UrlID);
        }
    }
}
